package mo.tags.stack;

import mo.common.ListNode;

import java.util.Stack;

public class L2130 {

    public int pairSum(ListNode head) {
        ListNode tmp = head;
        int len = 0;
        while (tmp != null) {
            len++;
            tmp = tmp.next;
        }
        Stack<Integer> stack = new Stack<>();
        tmp = head;
        int i = 0;
        while (i < len / 2) {
            stack.push(tmp.val);
            i++;
            tmp = tmp.next;
        }

        int max = 0;
        while (tmp != null) {
            max = Math.max(max, tmp.val+stack.pop());
            tmp = tmp.next;
        }
        return max;
    }

}
